<!doctype html> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台</title>
    <link href="/admin/css/default.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/admin/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/admin/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="/admin/kindeditor/themes/default/default.css" />
	<script charset="utf-8" type="text/javascript" src="/admin/kindeditor/kindeditor.js"></script>
    <script type="text/javascript" src="/admin/js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="/admin/js/jquery.easyui.min.js"></script>
	<?php
		if ($_REQUEST['lang'] == 'sc'){
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_CN.js'></script>";
			echo "<script charset='utf-8' type='text/javascript' src='/admin/kindeditor/lang/zh_CN.js'></script>";
		}else if ($_REQUEST['lang'] == 'tc'){
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_TW.js'></script>";
			echo "<script charset='utf-8' type='text/javascript' src='/admin/kindeditor/lang/zh_TW.js'></script>";
		}else{
			echo "<script type='text/javascript' src='./js/locale/easyui-lang-zh_CN.js'></script>";
			echo "<script charset='utf-8' type='text/javascript' src='/admin/kindeditor/lang/zh_CN.js'></script>";
		}
	?>
	<script type="text/javascript">
		var editor;
		KindEditor.ready(function(K) {
			editor = K.create('#editor_text', {
				width:'70%',
				height:'200px',
				items:[	'quickformat', 'preview','source','|','undo', 'redo', '|','template', 'cut', 'copy', 'paste',
						'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
						'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
						'superscript', 'clearhtml', 'selectall', '|', 'fullscreen', '/',
						'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
						'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
						'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'map', 'code', 'pagebreak',
						'link', 'unlink'
					],
				langType:<?php 
						if ($_REQUEST['lang'] == 'sc'){
							echo "'zh_CN'";
						}else if ($_REQUEST['lang'] == 'tc'){
							echo "'zh_TW'";
						}else{
							echo "'zh_CN'";
						}
						?>,
				designMode:true,
				minChangeSize:1,
				useContextmenu:true,
				allowFileManager:true,
				fontSizeTable:['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px','48px','64px','72px'],
				colorTable : [
					['#E53333', '#E56600', '#FF9900', '#64451D', '#DFC5A4', '#FFE500', '', '#642100', '#6C3365', '#003D79', '#3C3C3C', '#5B4B00', '#007500'],
					['#009900', '#006600', '#99BB00', '#B8D100', '#60D978', '#00D5FF', '', '#A23400', '#8F4586', '#005AB5', '#4F4F4F', '#AE8F00', '#00BB00'],
					['#337FE5', '#003399', '#4C33E5', '#9933E5', '#CC33E5', '#EE33EE', '', '#D94600', '#AE57A4', '#0080FF', '#6C6C6C', '#D9B300', '#00EC00'],
					['#FFFFFF', '#CCCCCC', '#999999', '#666666', '#333333', '#000000', '', '#FF5809', '#C07AB8', '#46A3FF', '#8E8E8E', '#FFD306', '#79FF79'],
					['#8080C0', '#336699', '#6699CC', '#479AC7', '#66CCCC', '#00B271', '', '#FF8F59', '#CA8EC2', '#84C1FF', '#ADADAD', '#FFE66F', '#A6FFA6'],
					['#DDF3FF', '#D5F3F4', '#D7FFF0', '#E8D098', '#F4A460', '#B45B3E', '', '#FFAD86', '#D2A2CC', '#ACD6FF', '#BEBEBE', '#FFF0AC', '#CEFFCE'],
					['#F1FAFA', '#E8FFE8', '#E8E8FF', '#F2F1D7', '#EFEFDA', '#F0DAD2', '', '#FFCBB3', '#E2C2DE', '#D2E9FF', '#E0E0E0', '#FFF8D7', '#DFFFDF'],
					['#EEEEEE', '#F0F8FF', '#FFFACD', '#F5FFFA', '#E6E6FA', '#C0C0C0', '', '#FFE6D9', '#EBD3E8', '#ECF5FF', '#F0F0F0', '#FFFCEC', '#F0FFF0']
				],
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						save($('#title').val(),editor.html());
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						save($('#title').val(),editor.html());
					});
				}
			});
			$('#title').validatebox({  
				required:true  
			});
			$.ajax({
				url: "/interface.php",
				async: true,
				type:'POST',
				dataType:'json',
				data:{type:'editor',lang:'<?php echo $_REQUEST['lang'];?>',part:'<?php echo $_REQUEST['part'];?>',action:'<?php echo $_REQUEST['action'];?>',id:'<?php echo $_REQUEST['id'];?>'},
				success: function(msg){
					if (msg != 'fail'){
						$('#title').val(msg.title);
						editor.html(msg.contect);
					}
				}
			});
			$('#save').click(function(){
				save($('#title').val(),editor.html());
			});
		});
	function save(t,c){
		<?php
			if ($_REQUEST['lang'] == 'sc'){
				echo "$.messager.confirm('同步确认','是否将当前数据同步到繁体数据段中？（注意：同步会直接覆盖当前繁体版的数据，请谨慎选择）',";
			}else if ($_REQUEST['lang'] == 'tc'){
				echo "$.messager.confirm('同步確認','是否將當前數據同步到繁體數據段中？（註意：同步會直接覆蓋當前繁體版的數據，請謹慎選擇）',";
			}else{
				echo "$.messager.confirm('同步确认','是否将当前数据同步到繁体数据段中？（注意：同步会直接覆盖当前繁体版的数据，请谨慎选择）',";
			}
		?>
		function(r){  
			if (r){  
				$.ajax({
					url: "/interface.php",
					async: true,
					type:'POST',
					dataType:'json',
					data:{type:'editor',lang:'<?php echo $_REQUEST['lang'];?>',part:'<?php echo $_REQUEST['part'];?>',action:'save',id:'<?php echo $_REQUEST['id'];?>',title:t,contect:c,langchange:1},
					success: function(msg){
						if (msg == 'success'){
							$.messager.alert('成功','修改成功！','info',function(){
								var title = window.parent.$('#tabs').tabs('getSelected').panel('options').tab.text();
								window.parent.$('#tabs').tabs('close',title);
							});
						}else{
							<?php
								if ($_REQUEST['lang'] == 'sc'){
									echo "$.messager.alert('失败','修改失败！');";
								}else if ($_REQUEST['lang'] == 'tc'){
									echo "$.messager.alert('失敗','修改失敗！');";
								}else{
									echo "$.messager.alert('失败','修改失败！');";
								}
							?>
						}
					},
					error:function(){
						<?php
							if ($_REQUEST['lang'] == 'sc'){
								echo "$.messager.alert('失败','修改失败！');";
							}else if ($_REQUEST['lang'] == 'tc'){
								echo "$.messager.alert('失敗','修改失敗！');";
							}else{
								echo "$.messager.alert('失败','修改失败！');";
							}
						?>
					}
				});
			}else{
				$.ajax({
					url: "/interface.php",
					async: true,
					type:'POST',
					dataType:'json',
					data:{type:'editor',lang:'<?php echo $_REQUEST['lang'];?>',part:'<?php echo $_REQUEST['part'];?>',action:'save',id:'<?php echo $_REQUEST['id'];?>',title:t,contect:c,langchange:0},
					success: function(msg){
						if (msg == 'success'){
							$.messager.alert('成功','修改成功！','info',function(){
								var title = window.parent.$('#tabs').tabs('getSelected').panel('options').tab.text();
								window.parent.$('#tabs').tabs('close',title);
							});
						}else{
							<?php
								if ($_REQUEST['lang'] == 'sc'){
									echo "$.messager.alert('失败','修改失败！');";
								}else if ($_REQUEST['lang'] == 'tc'){
									echo "$.messager.alert('失敗','修改失敗！');";
								}else{
									echo "$.messager.alert('失败','修改失败！');";
								}
							?>
						}
					},
					error:function(){
						<?php
							if ($_REQUEST['lang'] == 'sc'){
								echo "$.messager.alert('失败','修改失败！');";
							}else if ($_REQUEST['lang'] == 'tc'){
								echo "$.messager.alert('失敗','修改失敗！');";
							}else{
								echo "$.messager.alert('失败','修改失败！');";
							}
						?>
					}
				});
			}  
		});
	}
	</script>
</head>
<body>
	<noscript>
		<div style=" position:absolute; z-index:100000; height:2046px;top:0px;left:0px; width:100%; background:white; text-align:center;">
			<img src="images/noscript.gif" alt='抱歉，请开启脚本支持！' />
		</div>
	</noscript>
	<div id="new">
		<?php
			if(in_array($_REQUEST['part'],array('news','services','projects'))){
				echo "<p style='line-height:1.5em;'><label for='title'><b>标题：</b></label><input id='title' size='90'></div></p>";
			}else{
				echo "<p style='line-height:1.5em;display:none;'><label for='title' style='display:none;'><b>标题：</b></label><input id='title' size='90' style='display:none;'></div></p>";
			}
		?>
		<label for="editor" style="line-height:1.5em;display: block;margin-bottom:6px;"><b>内容：</b></label>
		<textarea id="editor_text" name="content"></textarea>
		<input id="save" type="submit" value="提交" /> (提交快捷键: Ctrl + Enter)
	</div>
</body>
</html>